package com.zhipu.balance.ui.vm.home.calculate.corn

import android.text.TextUtils
import androidx.databinding.ObservableField
import com.zhipu.balance.mobile.event.Personnel
import com.zhipu.balance.mobile.event.RecordCorn
import com.zhipu.balance.mobile.event.RecordWheat
import com.zhipu.balance.remotedata.systemapi.SystemApiService
import com.zhipu.balance.ui.vm.BaseViewModel
import com.zhipu.balance.utils.CommonUtils

/**
 * 玉米容重
 */
class CornRongZhongViewModel(mSystemApiService : SystemApiService) : BaseViewModel(mSystemApiService){


    /**
     * 重量
     */
    var weighing : String? = null

    /**
     * 玉米实体
     */
    var mRecordCorn : RecordCorn? = null


    /**
     * 当前的检查人员
     */
    var mPersonnel : Personnel? = null


    /**
     * 容重-质量
     */
    var densityQuality = ObservableField("")

    /**
     * 体积
     */
    var volume = ObservableField("")

    /**
     * 容重-结果
     */
    var densityResult = ObservableField("")



    /**
     * 更新页面
     */
    fun updateRecordRice(){
        if(!TextUtils.isEmpty(mRecordCorn?.densityRecorder)){
            //容重-质量
            densityQuality.set(mRecordCorn?.densityQuality.toString())


            //容重-结果
            densityResult.set(mRecordCorn?.densityResult.toString())
        }
    }


    /**
     * 释放更新页面
     */
    fun releaseRecordRice(){
        //容重-质量
        densityQuality.set("")
        //体积
        volume.set("")
        //容重-结果
        densityResult.set("")

    }




    /**
     * 容重-质量
     */
    fun densityQuality(){
        densityQuality.set(weighing)
        mRecordCorn?.densityQuality = densityQuality.get()?.toDouble()
    }


    /**
     * 计算
     */
    fun calculation(){
        /**
         * 容重-结果
         */
        var UnitWeight = if(TextUtils.isEmpty(volume.get())){
            (mRecordCorn?.densityQuality!! / 1)
        }else{
            (mRecordCorn?.densityQuality!! / volume.get()?.toDouble()!!)
        }
        mRecordCorn?.densityResult = CommonUtils.formatDouble(UnitWeight)
        densityResult.set(mRecordCorn?.densityResult.toString())


        /**
         * 容重记录员
         */
        mRecordCorn?.densityRecorder = mPersonnel?.name


        /**
         * 容重-质量
         */
        if(mRecordCorn?.densityQuality == 0.00){
            densityQuality.set("0.00")
        }





    }


}